package com.example.pf4j.controller;

import com.example.pf4j.service.SayHello;
import org.pf4j.PluginManager;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
public class Pf4jController {

    Logger logger = LoggerFactory.getLogger(getClass());

    @Autowired
    private PluginManager pluginManager;

    @RequestMapping("/sayHello")
    public void sayHello() throws Exception {
        List<SayHello> sayHellos = pluginManager.getExtensions(SayHello.class);
        for (SayHello sayHello : sayHellos) {
            logger.info(sayHello.sayHello("xxxxxxxxx"));
        }
    }
}
